<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="../../../attr.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!doctype html>
<html>
<meta http-equiv="X-UA-Compatible" content="IE=emulateIE7" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="${ctx}/css/sapar.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/css/common.css" />
<script type="text/javascript" src="${ctx}/js/jquery.js"></script>
<script type="text/javascript" src="${ctx}/js/sapar.js"></script>
<script type="text/javascript" src="${ctx}/js/WdatePicker.js"></script>
<script type="text/javascript" src="${ctx}/assets/layer/layer.js"></script>
<script type="text/javascript" src="${ctx}/js/kkpager.min.js"></script>
<link rel="stylesheet" type="text/css" href="${ctx}/css/kkpager_blue.css" />
<script type="text/javascript" src="${ctx}/assets/laydate/laydate.js"></script>

<title>包使用记录</title>
<style>
#tt{
width:150px;
}
th{
text-align: center;
}
td{
text-align: center;
}
#chazhaozhi{
margin-left:10px;
}
#tiaojian{
width:100px;
}
.nav_list{
float:left;
margin-left: 30px;
}
.nav_list ul{float:left}
.nav_list ul li{float:left;padding: 0 10px;height: 30px;;line-height: 30px;font-size: 14px;color: #333}
.nav_list ul li.native{background-color:#6ab96e;color: #fff}
</style>
</head>

<body>
<div id="mask" class="mask"></div>
    <div id="saper-container">
        <div id="saper-hd"></div>
        <div id="saper-bd">
            <div class="subfiled clearfix">
                <h2>包使用记录</h2>
            </div>
            <div class="subfiled-content">
                <div class="search-box clearfix">
                    <div class="kv-item clearfix">
                      <!--  -->  <label>类型查找：</label>
                        <!-- <div class="kv-item-content">
                            <select class="search_text" id="tiaojian">
                                <option value="">选择查找类型</option>
                                <option value="shiyongLiushui">使用流水</option>
                                <option value="wupinbaoTiaoma">物品包条码</option>
                                <option value="wupinbaoMingcheng">物品包名称 </option>
                                <option value="shiyongkeshi">使用科室 </option>
                                <option value="patientId">病人编号</option>
                            </select>
                        </div> -->
                    </div>
                    <div class="kv-item clearfix" id="chazhaozhi">
                       
                        <div class="kv-item-content">
                            <input type="text" name="searchTxt" value="${tiaojian }" placeholder="包条码/使用科室/病人编号" id="tt"  class="search_text" onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')">
                        </div>
                    </div>
                    
                     <div class="kv-item clearfix">
                        <!-- <label>最近时间：</label> -->
                       <div class="nav_list">
                       		<span>起始时间:</span>
                        	<input type="text" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})" value="<fmt:formatDate value='${startTime}' type='date' pattern='yyyy-MM-dd HH:mm:ss'/>" id="st" name="startTime" placeholder="起始时间" readonly="readonly">
                        	<span>终止时间:</span>
                        	<input type="text" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})" value="<fmt:formatDate value='${endTime}' type='date' pattern='yyyy-MM-dd HH:mm:ss'/>" id="et" name="endTime" placeholder="终止时间"  readonly="readonly">
                       </div>
                       <script>
                       	$(function(){
                       		$(".nav_list li").on("click",function(){
                       			$(this).addClass("native").siblings().removeClass("native");              
                       			window.location.href="${ctx}/shoushubaoshiyong/shoushubaoRecord.do?quzhi="+$(this).attr("value");
                       		});
                       	});
                       </script>
                    </div>
                    <a href="javascript:;" class="sapar-btn sapar-btn-recom query-btn">查询</a>
                </div>
                <!--表格开始-->
                <div class="table">
                    <!--表格操作-->
                    <div class="table-operate ue-clear">
                        <a href="javascript:;" class="add">添加</a>
						<!-- <a href="javascript:;" class="edit">修改</a>
                        <a href="javascript:;" class="del">删除</a> -->
                    </div>
                    <!--表格具体内容-->
                    <div class="table-box">
                        <table>
                            <thead>
                                <tr>
                                	<th><input type="checkbox" id="checkall" name="checkall"/></th>
                                    <th> 使用流水</th>
                                    <th>  物品包条码</th>
                                    <th>物品包名称</th>
                                    <th>使用科室</th>
                                    <th> 病人编号</th>
                                    <th>病人住院号 </th>
                                    <th> 手术模板</th>
                                      <th> 备注</th>
                                        <th>使用时间</th>
                                    <th>记录日期</th>
                                </tr>
                            </thead>
                            <tbody>
									<c:if test="${fafangList != null}">
										<c:forEach items="${fafangList}" var="fafang">
											<tr data="${fafang.shiyongLiushui}"
												 class="ycpdata">
												<td><input type="checkbox" name="key"
													value="${fafang.shiyongLiushui}" /></td>
														<td>${fafang.shiyongLiushui}</td>
														<td>${fafang.wupinbaoTiaoma}</td>
														<td>${fafang.wupinbaoMingcheng}</td>
														<td>${fafang.department.departmentName}</td>
														<td>${fafang.patientId}</td>
														<td>${fafang.patientHospitalNo}</td>
														<td>${fafang.shoushuTemplate}</td>
														<td>${fafang.beizhu}</td>
												<td><fmt:formatDate value="${fafang.shiyongTime}"
														type="date" pattern="yyyy-MM-dd  HH:mm:ss" /></td>
														<td><fmt:formatDate value="${fafang.recordTime}"
														type="date" pattern="yyyy-MM-dd HH:mm:ss" /></td>
											</tr>
										</c:forEach>
									</c:if>
								</tbody>
                        </table>
                    </div>
                </div><!--表格结束-->
            </div>
        </div>
        <div id="saper-ft">
       	 	<div id="kkpager"></div>
        </div>
    </div>
    
</body>

<script type="text/javascript">
	$(function(){
		
		var startTime=$("#st").val();  
        var start=new Date(startTime.replace("-", "/").replace("-", "/"));  
        var endTime=$("#et").val();  
        var end=new Date(endTime.replace("-", "/").replace("-", "/"));
		
		
		var totalPage = ${total};
		var pageNo = getParameter('pageIndex');
		if(!pageNo){
			pageNo = 1;
		}
		//生成分页
		//有些参数是可选的，比如lang，若不传有默认值
		kkpager.generPageHtml({
			pno : pageNo,
			//总页码
			total : totalPage,
			//链接前部
			hrefFormer : '${ctx}/shoushubaoshiyong/shoushubaoRecord',
			//链接尾部
			hrefLatter : '.do',
			getLink : function(n){
				return this.hrefFormer + this.hrefLatter + "?pageIndex="+n+"&searchTxt="+$(".search_text").val()+"&startTime="+startTime+"&endTime="+endTime;
			}
		});
		
		$(".query-btn").click(function(){
			startTime=$("#st").val();  
	        start=new Date(startTime.replace("-", "/").replace("-", "/"));  
	        endTime=$("#et").val();  
	        end=new Date(endTime.replace("-", "/").replace("-", "/"));  
	        if(end<start){  
	           alert("终止时间不能在起始时间之前");  
	        }  
			window.location.href="${ctx}/shoushubaoshiyong/shoushubaoRecord.do?searchTxt="+$(".search_text").val()+"&startTime="+startTime+"&endTime="+endTime;
		});
		
		$(".add").click(function(){
			window.location.href="${ctx}/shoushubaoshiyong/shoushubaoEdit.do";
		});
		$("#checkall").click(function(){
	   		   if(this.checked){
	   		        $("input[name='key']").prop('checked', true)
	   		    }else{
	   		        $("input[name='key']").prop('checked', false)
	   		    }

		    });

		
		$(".edit").click(function(){
			var chk_value = getSelRecord();
			if(chk_value.length == 1){
				window.location.href="${ctx}/shoushubaoshiyong/shoushubaoEdit.do?id="+chk_value[0];
			}else{
				layer.msg("请选择并只能选择一条数据！");
			}
		});
		
		$(".del").click(function(){
			var chk_value = getSelRecord();
			if(chk_value.length > 0){
				layer.confirm('你确定要删除么？', function(){
					$.ajax({
			             type: "POST",
			             url:"${ctx}/shoushubaoshiyong/shoushubaoDel.do?id="+chk_value.join(),
			             error: function(request) {
			            	 	layer.alert("网络故障，请稍后再试!");
			             },
			             success: function(data) {
			 	           	if(data.status=="true"){
				 	           	layer.alert("删除成功", function(){
				 	           		window.location.reload();
					 	           	$('input[name="key"]').each(function(){
				 	           		    $('input[name="key"]').prop("checked",false);
				 	           		});
			           		    });
			 	           	}else{
			 	           		layer.msg(data.msg);
			 	           	}
			             }
			         });
				});
			}else{
				layer.msg('请选择要删除的数据！');
			}
		});
	});
	
	function getSelRecord(){
		var chk_value =[];
		$('input[name="key"]:checked').each(function(){
			chk_value.push($(this).val()); 
		});
		return chk_value;
	}  
	
  	function getParameter(name) { 
		var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); 
		var r = window.location.search.substr(1).match(reg); 
		if (r!=null) return unescape(r[2]); return null;
	}
</script>
</html>